import 'package:casdon/build_gen/assets.gen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

// class CommonLoadingWidget extends StatelessWidget {
//   final double size;
//   final double strokeWidth;
//   final Color? color;
//   final double verticalPadding;

//   const CommonLoadingWidget({
//     super.key,
//     this.size = 24.0,
//     this.strokeWidth = 2.5,
//     this.color,
//     this.verticalPadding = 80.0,
//   });

//   @override
//   Widget build(BuildContext context) {
//     return SizedBox(
//       height: verticalPadding.h,
//       child: Center(
//         child: SizedBox(
//           width: size.w,
//           height: size.w,
//           child: CircularProgressIndicator(
//             strokeWidth: strokeWidth,
//             valueColor: AlwaysStoppedAnimation<Color>(
//               color ?? Theme.of(context).colorScheme.primary,
//             ),
//           ),
//         ),
//       ),
//     );
//   }
// }

class CommonLoadingWidget extends StatefulWidget {
  final double radius;
  final Color? color;

  const CommonLoadingWidget({super.key, this.radius = 36, this.color});

  @override
  State<CommonLoadingWidget> createState() => _CommonLoadingWidgetState();
}

class _CommonLoadingWidgetState extends State<CommonLoadingWidget>
    with SingleTickerProviderStateMixin {
  late final AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      vsync: this,
      duration: const Duration(seconds: 1),
    )..repeat();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: RotationTransition(
        turns: _controller,
        child: Assets.images.icLoading.image(
          width: widget.radius.w * 2,
          height: widget.radius * 2,
          color: widget.color,
        ),
      ),
    );
  }
}

// 使用方式
